package com.flyan.game.motafx.core.panel;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.flyan.game.motafx.MotaApp;
import com.flyan.game.motafx.component.BackpackComponent;
import com.flyan.game.motafx.component.EquipSlotsComponent;
import com.flyan.game.motafx.component.character.BraveComponent;
import com.flyan.game.motafx.core.consts.PropertyConsts;
import com.flyan.game.motafx.core.pojo.LifePanel;
import com.flyan.game.motafx.core.util.entity.EntityUtils;

/**
 * 游戏信息面板
 *
 * @author flyan
 * @version 1.0
 * @email flyan_by_chenu@sina.com
 * @since 2025/2/6
 */
public class GameInfoPanel {

    /**
     * 重绘并更新到 ui 面板
     */
    public void drawToUiPane() {
        MotaApp app = (MotaApp) FXGL.getApp();
        Entity braveEntity = app.braveEntityLv.get();

        /* 左测信息栏 */
        if (app.leftInfoPane != null) {
            /* 渲染所处楼层 */
            BraveComponent braveComponent = braveEntity.getComponent(BraveComponent.class);
            app.leftInfoPane.getFloorInfo().setText("魔塔 %d 层".formatted(braveComponent.getFloor().getFloorInfo().getNumber()));

            /* 生命面板 */
            LifePanel lifePanel = EntityUtils.getEntityProperty(braveEntity, PropertyConsts.LIFE_PANEL, LifePanel.class);
            app.leftInfoPane.getHpInfo().setText(lifePanel.getHp() + "");
            app.leftInfoPane.getAckInfo().setText(lifePanel.getAck() + "");
            app.leftInfoPane.getDefInfo().setText(lifePanel.getDef() + "");
            app.leftInfoPane.getGoldInfo().setText(lifePanel.getGold() + "");

            /* 道具 */

            /* ui 更新 */
            app.leftInfoPane.update();
        }



        /* 右测信息栏 */
        if (app.rightInfoPane != null) {
            /* 装备栏 */
            EquipSlotsComponent equipSlotsComponent = braveEntity.getComponent(EquipSlotsComponent.class);
            app.rightInfoPane.setEquipSlotsComponent(equipSlotsComponent);

            /* 钥匙盒子 */
            BackpackComponent backpackComponent = braveEntity.getComponent(BackpackComponent.class);
            app.rightInfoPane.setBackpackComponent(backpackComponent);

            /* ui 更新 */
            app.rightInfoPane.update();
        }
    }

    public static void redraw() {
        ((MotaApp) FXGL.getApp()).gameInfoPanel.drawToUiPane();
    }

}
